﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace B10.Helpers
{
    public static class UserHelper
    {
        public static int? UserId
        {
            get
            {
                HttpContext context = HttpContext.Current;
                if (context == null)
                    return null;
                if (!context.Request.IsAuthenticated)
                    return null;
                if (context.User == null || context.User.Identity == null
                    || String.IsNullOrEmpty(context.User.Identity.Name))
                    return null;
                int id;
                if (Int32.TryParse(context.User.Identity.Name, out id))
                    return id;
                return null;
            }
        }

        public static string UserIdAsString
        {
            get
            {
                HttpContext context = HttpContext.Current;
                if (context == null)
                    return null;
                if (!context.Request.IsAuthenticated)
                    return null;
                if (context.User == null || context.User.Identity == null
                    || String.IsNullOrEmpty(context.User.Identity.Name))
                    return null;
                return context.User.Identity.Name;
            }
        }
    }
}
